package com.jqr.activity.mvvmdemo;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.MutableLiveData;

public class MainViewModel extends AndroidViewModel {

    private  int num=0;
    public MainViewModel(@NonNull Application application) {
        super(application);
    }
    MutableLiveData<Integer> number=new MutableLiveData<>();


    public  void add(){
        num++;
        number.setValue(num);

    }

    public  void minus(){

        if(num>0){
            num--;
            number.setValue(num);
        }
        else {
            num=0;
        }
    }




}
